package project.parser.ast.aux;

import project.environments.Value;
import project.parser.ast.exps.Ident;

import java.util.HashMap;
import java.util.Map;

public class Record {
	private final Map<Ident,Value> valuesMap;

	public Record(Map<Ident,Value> valuesMap) {
		if (valuesMap == null)
			valuesMap = new HashMap<>();
		this.valuesMap = valuesMap;
	}

	public Map<Ident,Value> getValuesMap() {
		return new HashMap<>(valuesMap);
	}

	public Value getFieldValue(Ident fieldId) {
		return valuesMap.get(fieldId);
	}

	public void setFieldValue(Ident fieldId, Value fieldValue) {
		if (valuesMap.put(fieldId, fieldValue) == null)
			throw new IllegalArgumentException("Field '" + fieldId + "' does not exist in this record");
	}

	@Override
	public String toString() {
		return valuesMap.toString();
	}
}
